// ==========================================================================
// FormToggle
// ==========================================================================

.form-toggle[type='checkbox'] {
	display: none;
}

.form-toggle__switch {
	position: relative;
	display: inline-block;
	border-radius: 12px;
	box-sizing: border-box;
	padding: 2px;
	width: 40px;
	height: 24px;
	vertical-align: middle;
	align-self: flex-start;
	outline: 0;
	cursor: pointer;
	transition: all 0.4s ease, box-shadow 0s;

	&::before,
	&::after {
		position: relative;
		display: block;
		content: '';
		width: 20px;
		height: 20px;
	}
	&::after {
		left: 0;
		border-radius: 50%;
		background: var( --color-surface );
		transition: all 0.2s ease;
	}
	&::before {
		display: none;
	}
	.accessible-focus &:focus {
		box-shadow: 0 0 0 2px var( --color-primary );
	}
}

.form-toggle__label {
	cursor: pointer;

	.is-disabled & {
		cursor: default;
	}

	.form-toggle__label-content {
		flex: 0 1 100%;
		margin-left: 12px;
	}
}

.form-toggle {
	.accessible-focus &:focus {
		+ .form-toggle__label .form-toggle__switch {
			box-shadow: 0 0 0 2px var( --color-primary );
		}
		&:checked + .form-toggle__label .form-toggle__switch {
			box-shadow: 0 0 0 2px var( --color-primary-light );
		}
	}

	& + .form-toggle__label .form-toggle__switch {
		background: var( --color-neutral-20 );
	}

	&:not( :disabled ) {
		+ .form-toggle__label:hover .form-toggle__switch {
			background: var( --color-neutral-10 );
		}
	}

	&:checked {
		+ .form-toggle__label .form-toggle__switch {
			background: var( --color-primary );

			&::after {
				left: 16px;
			}
		}
	}

	&:checked:not( :disabled ) {
		+ .form-toggle__label:hover .form-toggle__switch {
			background: var( --color-primary-light );
		}
	}

	&:disabled {
		+ label.form-toggle__label span.form-toggle__switch {
			opacity: 0.25;
			cursor: default;
		}
	}
}

// Classes for toggle state before action is complete (updating plugin or something)
.form-toggle.is-toggling {
	+ .form-toggle__label .form-toggle__switch {
		background: var( --color-primary );
	}
	&:checked {
		+ .form-toggle__label .form-toggle__switch {
			background: var( --color-neutral-10 );
		}
	}
}
